# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

import csv
    

# Item Pipeline用来处理返回的Item数据
class ErshouchePipeline:
    def __init__(self):
        #with open('beijingdata1.csv', 'w',newline ="",encoding="utf-8") as f:
        f = open("beijingdata1.csv","w",newline="",encoding="utf-8")    
        #newline避免出现间隔一行
        
        # 创建csv文件的写入器对象
        self.writer = csv.writer(f) 

         # 写入标题行
        self.writer.writerow(["brand","price","information"])  

    def process_item(self, item, spider):
        
        # 将每个Item对象的数据brand,price,mileage写入csv文件
        self.writer.writerow([item["brand"],item["price"],item["information"]])
